package com.xuzao.developer.controller;

import com.xuzao.developer.base.model.ProjectVersion;
import com.xuzao.developer.dto.ProjectVersionDTO;
import com.xuzao.developer.service.ProjectVersionService;
import com.xuzao.developer.utils.BJUIMap;
import com.xuzao.developer.tools.entity.Pager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @description 
 * @author xuzao
 * @date 2019-08-09 18:12:00
 **/
@Controller
@RequestMapping("/projectVersion/")
public class ProjectVersionController{

	@Resource
	private ProjectVersionService projectVersionService;

	@RequestMapping("queryList")
	public String queryList(ProjectVersionDTO dto, Pager pager, Model model) {
		model.addAttribute("list",projectVersionService.list(dto,pager));
		return "/project_version/project_version_list";
	}

	@RequestMapping("add")
	public String add(Model model){
		ProjectVersion bo = new ProjectVersion();
		model.addAttribute("bo",bo);
		return "/project_version/project_version_add";
	}

	@RequestMapping("update")
	public String update(Model model,Long id){
		ProjectVersionDTO bo = new ProjectVersionDTO();
		bo.setId(id);
		model.addAttribute("bo",projectVersionService.get(bo));
		return "/project_version/project_version_update";
	}

	@RequestMapping("save")
	@ResponseBody
	public BJUIMap save(ProjectVersionDTO dto){
		if (StringUtils.isNotBlank(dto.getFlag())){
			projectVersionService.update(dto);
		}else{
			projectVersionService.insert(dto);
		}

		BJUIMap map = new BJUIMap();
		map.setMessage("操作成功");
		map.setTabid("projectVersion");
		map.setCloseCurrent(BJUIMap.CALLBACK_CLOSE);
		map.setStatusCode(BJUIMap.CODE_OK);
		return  map;
	}

	@RequestMapping("del")
	@ResponseBody
	public BJUIMap del(ProjectVersionDTO dto){
		projectVersionService.del(dto.getId());
		BJUIMap map = new BJUIMap();
		map.setMessage("操作成功");
		map.setTabid("projectVersion");
		map.setStatusCode(BJUIMap.CODE_OK);
		return  map;
	}


}